<template>
	<view class="container_tab">
		<view class="container_body">
			<view class="head" >
				<picker mode="selector" @change="communityChange" :value="headindex" :range="[currentcommunityName]">
					<view class="headbody" >
						<image class="location" src="../../../static/index/location2x.png"></image>
						<text class="community">{{currentcommunityName}}</text>
					</view>
				</picker>
			</view>
			<view class="swiperbox" >
				<swiper class="swiper" circular :indicator-dots="swiper.indicatorDots" :autoplay="swiper.autoplay"
					:interval="swiper.interval" :duration="swiper.duration" >
					<swiper-item v-for="item in swiper.data" :key="item.id" @click="swipergoPage(item)">
						<view class="swiper-item ">
							<img-item class="swiper-img" :src="item.imageUrl"></img-item>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="indexbody" >
				<view class="nav">
					<view class="nav_item nav_llxt" @click="goPage('/pages/school/index/index')">
						<text class="nav_title">邻里学堂</text>
					</view>
					<view class="nav_item nav_jyhd" @click="goPage('/pages/activity/list/list')">
						<text class="nav_title">教育活动</text>
					</view>
					<view class="nav_item nav_rrwx" @click="goPage('/pages/onlineschool/index/index')"><!-- /pages/web/index -->
						<text class="nav_title">人人网校</text>
					</view>
					<view class="nav_item nav_drms" @click="goPage('/pages/talents/talents')">
						<text class="nav_title">达人民师</text>
					</view>
					<view class="nav_item nav_hpyt" @click="goPage('/pages/childcare/detail/index')">
						<text class="nav_title">普惠幼托</text>
					</view>
					<view class="nav_item nav_jzdx" @click="goPage(null)">
						<text class="nav_title">家长大学</text>
					</view>
				</view>
				<view class="section" v-if="schoolList">
					<view class="section_head">
						<text class="section_title">邻里学堂</text>
						<text class="section_more" @click="goPage('/pages/school/index/index')">查看全部 ></text>
					</view>
					<view class="section_items item_list">
						<view class="item " v-for="v in schoolList" :key="v.id" @click="goPage('/pages/school/detail/index',{id:v.id})">
							<view class="item_img">
								<img-item :src="v.cover"></img-item>
							</view>
							<view class="item_info">
								<view class="item_title">{{v.name}}</view>
								<view class="item_sign">
									<view class="sign_one">{{v.courseNodes}}节</view>
									<view class="sign_item" v-for="(sv,sk) in v.courseLabelList" :key="sk">{{sv}}</view>
								</view>
								<view class="item_class">{{v.institutionName}}</view>
								<view class="item_time">上课时间：{{v.openTime}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="section" v-if="activityList">
					<view class="section_head">
						<text class="section_title">教育活动</text>
					</view>
					<view class="section_items row2">
						<view class="item" v-for="v in activityList" :key="v.id" @click="goPage('/pages/activity/detail/index',{id:v.id})">
							<view class="item_img">
								<img-item :src="v.poster"></img-item>
							</view>
							<view class="item_info">
								<view class="item_title">{{v.name}}</view>
								<view ><rich-text class="item_introduction" :nodes="v.introduce"></rich-text></view>
							</view>
						</view>
					</view>
				</view>
				<view class="section">
					<view class="section_head">
						<text class="section_title">人人网校</text>
						<text class="section_more" @tap="goPage('/pages/onlineschool/index/index')">查看全部 ></text>
					</view>
					<view class="section_items row4">
						<view class="item" v-for="v in oschoolNav" :key="v.id" @tap="goPage('/pages/onlineschool/schoolList/index',{id:v.playUrl,title:v.title})">
							<view class="item_img">
								<img-item :src="v.hPic"></img-item>
							</view>
							<view class="item_info">
								<view class="item_title">{{v.title}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="section">
					<view class="section_items extend">
						<view class="item" v-for="v in oschoolList" :key="v.id" @tap="goVideoPlay(v.id)">
							<view class="item_img">
								<img-item :src="v.hPic"></img-item>
							</view>
							<view class="item_info">
								<view class="item_title">{{v.title}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="section" v-if="talentList">
					<view class="section_head">
						<text class="section_title">达人姓名</text>
						<text class="section_more" @click="goPage('/pages/talents/talents')">查看全部 ></text>
					</view>
					<view class="section_items extendcard">
						<view class="item" v-for="v in talentList" :key="v.id" @click="goPage('/pages/talents/detail',{talentMobile:v.talentMobile})">
							<view class="itembody">
								<view class="item_img">
									<img-item :src="v.photo"></img-item>
								</view>
								<view class="item_info">
									<view class="item_title">{{v.name}}</view>
									<item-score :score="v.score"></item-score>
									<view class="item_sign">
										<view class="sign_item" v-for="(sv,sk) in v.skillList" :key="sk">{{sv}}</view>
									</view>
									<rich-text class="item_introduction" :nodes="v.introduction"></rich-text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import itemScore from "@/components/base/item-score.vue";
	import {
		homeBanner,
		homeBannerPublic,
		homeRecommend,
		homeRecommendPublic,
		recommendServlet
	} from "@/http/api";
	import {request} from "@/http/request";
	import {
		getUrlparas
	} from "@/common/util";
	import {
		mapActions,
		mapState
	} from 'vuex'
	export default {
		components:{itemScore},
		data() {
			return {
				headindex:0,
				headarray:[],
				swiper: {
					indicatorDots: true,
					autoplay: true,
					interval: 5000,
					duration: 500,
					data:[]
				},
				value: "",
				isLoading: false,
				page: 1,
				pagenum: 10, //每页加载10个数据
				talentList:null,
				activityList:null,
				schoolList:null,
				oschoolList:null,
				oschoolNav:null
			}
		},
		computed:{
			...mapState(['currentcommunityName','token']),
		},
		onShareAppMessage() {
			return {
				title: "欢迎体验未来社区",
				path: '/pages/tabBar/index/index?isRedirectUrl',
			}
		},
		methods: {
			communityChange(e){
				 this.headindex = e.detail.value;
			},
			intToWord(week){
				let day;
				switch (week) {
				  case 7:
				    day = "周日";
				    break;
				  case 1:
				    day = "周一";
				    break;
				  case 2:
				    day = "周二";
				    break;
				  case 3:
				    day = "周三";
				    break;
				  case 4:
				    day = "周四";
				    break;
				  case 5:
				    day = "周五";
				    break;
				  case  6:
				    day = "周六";
				}
				return day;
			},
			getData(){
				this.getHomeBanner();
				this.getHomeRecommend();
				this.getmcspRecommend();
			},
			getHomeBanner(){
				let url = ''   
				this.token ? url = homeBanner : url = homeBannerPublic
				this.$request({
					url: url,
					data: {}
				}).then(res => {
					this.swiper.data = res.slice(0,5);
				})
			},
			getHomeRecommend(){
				let url = ''
				this.token ? url = homeRecommend : url = homeRecommendPublic
				this.$request({
					url: url,
					data: {}
				}).then(res => {
					this.schoolList = res.neighborhoodSchoolList.slice(0,2);
					this.activityList = res.activityList?.length && res.activityList.slice(0,4);
					this.talentList = res.talentList.slice(0,4);
					this.weekTimeToStr();
					if(!res.todayFirstLoginStatus) return
					// uni.showToast({
					// 	title: '登录+5积分',
					// 	icon: 'none'
					// })
				})
			},
			weekTimeToStr(){
				this.schoolList.map((item,index) => {
					if (item&&item.classInfo&&item.classInfo.classTimeList) {
						let ot = item.classInfo.classTimeList;
						let openTime = '';
						for(let i in ot){
							let week = this.intToWord(ot[i].week);
							let t = ot[i].startTime.slice(0,-3) + '-' + ot[i].endTime.slice(0,-3);
							openTime = openTime + week + t + ' ';
						}
						item.openTime = openTime;
					}
					return item;
				})
				// console.log(this.schoolList);
			},
			getmcspRecommend(){
				let _data = {
					url: recommendServlet,
					data: {
						"functionName":"getRecommond",
						"modeId":328,
						"pageSize": 10,
						"page": 1
					}
				};
				request(_data).then((res) => {
					this.oschoolList = res.data[0].manualList;
					this.oschoolNav = res.data[1].manualList;
				})
			},
			swipergoPage(e){
				if(e.urlType=="OUTER"){
					this.goPage('/pages/onlineschool/index/index',e);
				}else{
					let _url = e.jumpUrl.substring(0, e.jumpUrl.indexOf("?"));
					let _obj = getUrlparas(e.jumpUrl);
					let gopage = '';
					switch(_url){
						case 'school':
						     gopage = '/pages/school/detail/index'
							 break;
						case 'activity':
						     gopage = '/pages/activity/detail/index'
							 break;
						case 'childcare':
						     gopage = '/pages/childcare/detail/index'
							 break;
						case 'talents':
						     gopage = '/pages/talents/detail'
							 break;
					}
					if(gopage)this.goPage(gopage,{id:_obj.id})
				}
			},
			dataProcess(obj){
				let _arr = obj.split(',');
				return {
					nodeId:_arr[0],
					newsId:_arr[1]
				}
			},
			goVideoPlay(id){
				this.toAutorize()
				this.goPage('/pages/onlineschool/videoplay/index',this.dataProcess(id))
			}
		}
	}
</script>
<style lang="scss">
	@import "./index.scss";
</style>
